package com.iter.devbox.juc;

import java.util.concurrent.Semaphore;

public class MySemaphore {

	private Semaphore sem = new Semaphore(10);
	
    public boolean tryLock(){
        boolean rs = false;
        try{
            sem.acquire(); //尝试获取，没有信号量时，不阻塞
        }catch(Exception e){
            e.printStackTrace();
        }
        return rs;
    }
 
    public boolean unlock() {
        sem.release(); //释放信号量
		return false;
    }

	public static void main(String[] args) {
		MySemaphore lock = new MySemaphore();
		 
        lock.tryLock();
        
        System.out.print("Job doPrint is working.");
        
        lock.unlock();
	}
}
